package com.coda.clouddisk.utils;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

public class EntityToMap {
    public static Map<String, Object> convertObjectToMap(Object obj) throws IllegalAccessException {
        Map<String, Object> map = new HashMap<>();
        Class<?> clazz = obj.getClass();

        while (clazz != null) {
            for (Field field : clazz.getDeclaredFields()) {
                field.setAccessible(true);
                map.put(field.getName(), field.get(obj));
            }
            clazz = clazz.getSuperclass();
        }

        return map;
    }
}
